package com.dance.sharevalidator.controller;

import com.dance.sharevalidator.entity.Dept;
import com.dance.sharevalidator.service.DeptService;
import com.dance.sharevalidator.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.time.LocalDateTime;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/dept")
//@Validated // <---- 通过这个注解让validation验证这个类
public class DeptController {

    @Autowired
    private DeptService deptService;

    /**
     * http://localhost:8080/dept
     * 添加部门
     * addRoot 添加根节点 parentId = 0
     * add
     *
     * @param dept 要添加的部门
     * @return 结果
     * @Valid <-----使用这个注解让 这个注解后面的参数被校验
     */
    @PostMapping
    public ResultVo<Object> add(@RequestBody /*@Valid*/ Dept dept) {
        // 终于可以开始写业务了
        deptService.add(dept);
        return ResultVo.success();
    }

}
